package tmproject.hlhj.fhp.cartrans.customVIews

import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.widget.PopupWindow
import android.widget.RelativeLayout
import kotlinx.android.synthetic.main.search_pop.view.*
import tmproject.hlhj.fhp.cartrans.R
import tmproject.hlhj.fhp.cartrans.adapter.ChooseNumAdp
import tmproject.hlhj.fhp.cartrans.javaBean.CarNumBean
import tmproject.hlhj.fhp.cartrans.log

/**
 * Created by Administrator on 2018/8/28/028.
 */
class ChooseNumPop(private val  c: Context,private var mWidth:Int) :PopupWindow(c) {
    var listener:OnNumSelectListener?=null
    private var chooseNumAdp:ChooseNumAdp?=null
    private val datas=ArrayList<CarNumBean.DataBean>()
    init {
        if (mWidth==0){
            this.width=RelativeLayout.LayoutParams.MATCH_PARENT
        }else{
            this.width=mWidth
        }
        this.height=RelativeLayout.LayoutParams.WRAP_CONTENT

        setPop()
    }

    private fun setPop(){
        contentView=LayoutInflater.from(c).inflate(R.layout.search_pop,null)

        chooseNumAdp=ChooseNumAdp(datas)

        contentView.recyclerview.adapter=chooseNumAdp
        contentView.recyclerview.layoutManager=LinearLayoutManager(c,LinearLayoutManager.VERTICAL,false)
        setData(datas)

        chooseNumAdp?.setOnItemClickListener { adapter, view, position ->
            listener?.selectNum(this.datas[position].id,this.datas[position].tractor_no)
            dismiss()
        }
    }
    fun setData(datas:ArrayList<CarNumBean.DataBean>){
        this.datas.clear()
        this.datas.addAll(datas)
        log("fhp","数据来了")
        chooseNumAdp?.notifyDataSetChanged()
    }
    interface OnNumSelectListener{
        fun selectNum(id:Int,num:String)
    }
}